﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Beyond;
using System;

public class AdsProxy {

    public static void init() {
        Ads.initialize(new Ads.CallbackDelegateE(adCallback));
        ShowAdSplash();
    }

    public static Action completeCallback = default;

    public static void ShowVideo(Action _completeCallback)
    {
        if (!Ads.isReady(Ads.Type.video))
        {
            string title = string.Empty;

            switch (GameManager.Instance.GameType)
            {
                case Enums.GameScenes.Klondike:
                    title = "KINGS KLONDIKE";
                    break;
                case Enums.GameScenes.Spider:
                    title = "KINGS SPIDER";
                    break;
                case Enums.GameScenes.Tripeaks:
                    title = "KINGS TRIPEAKS";
                    break;
            }

            DialogSystem.Instance.ShowDialogMessage("Video not ready", title, null,null,null);
            return;
        }
        completeCallback = _completeCallback;
        BELog.debug("AdmobController.ShowVideo");
        Ads.showAd(Ads.Type.video);
    }

    public static void ShowAdInterstitial()
    {
        BELog.debug("AdmobController.ShowInterstitial");
        Ads.showAd(Ads.Type.interstitial);
    }

    public static void HideBanner()
    {
        BELog.debug("AdmobController.HideBanner");
        Ads.hideAd(Ads.Type.banner);
    }

    public static void ShowBanner()
    {
        BELog.debug("AdmobController.ShowBanner");
        Ads.showAd(Ads.Type.banner);
    }

    public static void ShowAdSplash()
    {
        BELog.debug("AdmobController.ShowSplash");
        Ads.showAd(Ads.Type.splash);
    }

    /// <summary>
    /// 广告事件回调
    /// </summary>
    /// <param name="type">广告类型</param>
    /// <param name="eve">事件类型</param>
    static void adCallback(Ads.Type type, Ads.Event eve)
	{
		BELog.debug("AdsProxy.adCallback " + type + ", " + eve);
		if (eve >= Ads.Event.returned)
		{
            App.resume();
		}

        if (type == Ads.Type.video && eve == Ads.Event.returnedWithViewCompleted)
        {
            completeCallback?.Invoke();
            completeCallback = null;
        }
    }
}

